import 'package:flutter/material.dart';
import 'package:yqys_target/utils/yq_colors.dart';

class ProgressWidget extends StatelessWidget {
  final double progress;
  final String progressText;
  final String target;
  final double progressHeight;
  final List<Color> gradientColors;

  const ProgressWidget(
      {super.key,
      required this.progress,
      required this.progressText,
      required this.target,
      required this.gradientColors,
      this.progressHeight = 8});

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SizedBox(
          height: progressHeight,
          width: double.infinity,
          child: Stack(
            children: [
              // 背景
              Container(
                width: double.infinity,
                decoration: BoxDecoration(
                  color: Colors.grey[200],
                  borderRadius: BorderRadius.circular(progressHeight * 0.5),
                ),
              ),
              // 进度条
              FractionallySizedBox(
                widthFactor: progress,
                child: Container(
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                      colors: gradientColors,
                    ),
                    borderRadius: BorderRadius.circular(4),
                  ),
                ),
              ),
            ],
          ),
        ),
        const SizedBox(height: 8),
      ],
    );
  }
}

class ProgressInfo extends StatelessWidget {
  const ProgressInfo({
    super.key,
    required this.progressText,
    required this.target,
    this.raiseStatusTitle = '筹集中',
    this.raiseTargetTitle = '筹集目标',
    this.raiseStatusTitleFontSize = 13,
    this.raiseTargetTitleFontSize = 13,
  });

  final String progressText;
  final String target;
  final String? raiseStatusTitle;
  final String? raiseTargetTitle;
  final double? raiseStatusTitleFontSize;
  final double? raiseTargetTitleFontSize;

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        RichText(
          text: TextSpan(
            children: [
              TextSpan(
                text: "$raiseStatusTitle ",
                style: TextStyle(
                  color: YQColors.secondary,
                  fontSize: raiseStatusTitleFontSize,
                ),
              ),
              TextSpan(
                text: progressText,
                style: TextStyle(
                  color: YQColors.orangeColor,
                  fontSize: raiseStatusTitleFontSize! + 2.0,
                ),
              ),
            ],
          ),
        ),
        RichText(
          text: TextSpan(
            children: [
              TextSpan(
                text: '$raiseTargetTitle ',
                style: TextStyle(
                  color: YQColors.secondary,
                  fontSize: raiseTargetTitleFontSize,
                ),
              ),
              TextSpan(
                text: target,
                style: TextStyle(
                  color: YQColors.orangeColor,
                  fontSize: raiseTargetTitleFontSize! + 2.0,
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }
}
